package org.example.controller;

import cn.hutool.Hutool;
import cn.hutool.crypto.digest.DigestUtil;
import cn.hutool.crypto.digest.MD5;
import org.example.Imp.StudentServiceImp;
import org.example.StudentService;
import org.example.domain.Student;
import org.example.pageParam.CommonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 学生这个模板就不要做多余的操作 比如 教师中优秀改密码  退出系统 等 学生就不做了  主要是考试 老师不做我也不想做  应该会做............
 */
@Controller
public class LoginControllerS {
    @Autowired
    private StudentServiceImp studentServiceImp;
    @RequestMapping("/loginS.html")
    public String login(Student student){
        return "s_login_page";
    }
    @ResponseBody
    @RequestMapping("/common/loginVerifyS")
    public Boolean login(String mnemonic_code, String pass, HttpSession httpSession){
        Student student = studentServiceImp.selectStudentByMnemonic_code(mnemonic_code);
        if (student==null){
            return false;
        }
        pass = DigestUtil.md5Hex(pass);
        if (!pass.equals(student.getPass())){
            return false;
        }
        httpSession.setAttribute("loginStudent",student);
        return true;
    }
    @RequestMapping("/mainPageS.html")
    public String mainPage(){
        return "mainPage";
    }
    @RequestMapping("/timeoutS")
    public String timeout(){
        return "common/visitTimeOut";
    }
}
